/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AppServices;

import Facades.CityFacadeRemote;
import Facades.CountryFacadeRemote;
import VOs.City;
import VOs.Country;
import java.util.ArrayList;
import java.util.List;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Julian
 */
public class CountryCityManage {

    static public CountryFacadeRemote StartContextCountry() throws NamingException {
        InitialContext ctx = new InitialContext();
        CountryFacadeRemote cbeanremote = (CountryFacadeRemote) ctx.lookup("Facades.CountryFacadeRemote");
        return cbeanremote;
    }

    static public CityFacadeRemote StartContextCity() throws NamingException {
        InitialContext ctx = new InitialContext();
        CityFacadeRemote cibeanremote = (CityFacadeRemote) ctx.lookup("Facades.CityFacadeRemote");
        return cibeanremote;
    }

    static public List<Country> findall() throws Exception {

        try {
            return StartContextCountry().findAll();
        } catch (Exception ex) {
            throw ex;
        }
    }

        static public List<City> findallCity() throws Exception {

        try {
            return StartContextCity().findAll();
        } catch (Exception ex) {
            throw ex;
        }
    }

    static public List<City> findbyCountry(String Country) throws Exception {

        try {
            List<City> listtemp = StartContextCity().findAll();
            ArrayList<City> list = new ArrayList();
            for (int i = 0; i < listtemp.size(); i++) {
                if (listtemp.get(i).getFkCountry().getName().equals(Country)) {
                    System.out.println(listtemp.get(i));
                    list.add(listtemp.get(i));
                }
            }
            return list;
        } catch (Exception e) {
            throw e;
        }

    }
}
